<?php

class GTL_Controller_Plugin extends Zend_Controller_Plugin_Abstract {

    public function preDispatch(Zend_Controller_Request_Abstract $request) {
		/*
        //Create new Acl object
        $acl = new Zend_Acl();
        $aclModel = new Model_Acl();

        $roleControllerArray = Array();
        
        // define roles
        $rolesArray = $aclModel->getRoles();
        $rolesIdArray = array_flip($rolesArray);
        foreach ($rolesArray as $role_id => $_roles) {
            $acl->addRole(new Zend_Acl_Role($_roles));
        }

        // define resources. typically there are
        // but there can be added more resources
        $resourcesArray = $aclModel->getResources();
        foreach ($resourcesArray as $_controler => $_action) {
            $acl->addResource(new Zend_Acl_Resource($_controler));
        }

        $auth = Zend_Auth::getInstance();
        $storage = new Zend_Auth_Storage_Session(Zend_Registry::get('sessionName'));
        $auth->setStorage($storage);
        $user = $auth->getIdentity();

        if ($request->getModuleName() == 'admin') {

            //Check User is Logged In
            if ($user != null && $request->getControllerName() != 'logout') {
                if ($user->role == 'ADMIN') {
                    //Alow every thing to the ADMIN
                    $acl->allow($user->role);
                } else {
                    
                    $roleId = $rolesIdArray[$user->role];
                    $acessRoleModel = new Model_Roleaccess();
                    //Load the roles given by Admin
                    $roleAccessArray = $acessRoleModel->fetchEntryById($roleId);

                    //Define priveleges set by the Admin 
                    foreach ($roleAccessArray as  $_value) {
                        $roleControllerArray[$_value['ra_controller']][$_value['ra_action']] = true;
                        $acl->allow($user->role, $_value['ra_controller'], $_value['ra_action']);
                    }
                    
                    // define global privileges to all the user , this are the ajax functions
                    $GLOBAL_RESOURCES_ARRAY = $aclModel->getGlobalResources();
                    foreach ($GLOBAL_RESOURCES_ARRAY as $_controller => $_action) {
                        $acl->allow($user->role, $_controller, $_action);
                    }
                }

                // setup acl in the registry for more
                Zend_Registry::set('acl', $acl);
                Zend_Registry::set('role_access', $roleControllerArray);

                // check permissions
                if (!$acl->isAllowed($user->role, $request->getControllerName(), $request->getActionName())) {
                    $request->setControllerName('index');
                    $request->setActionName('unauthorized');
                }
            }
        }
		*/
    }

}

?>